import React, { PureComponent } from "react";
import { connect } from "dva";
import router from 'umi/router';
import { Card, Table, Badge } from "antd";
import styles from "./component.less";




@connect(({ monitor, loading }) => ({
  TableData:monitor.currentMaintenance,
  loading: monitor.loading.currentMaintenance,
}))
export default class Dashboard extends PureComponent {
  constructor(props) {
    super(props);

  }

  componentDidMount() {
    this.getData();
    this.timerID = setInterval(
      () => this.getData(),
      1000*60*2
    );

  }

  componentWillUnmount() {
    clearInterval(this.timerID);
  }


  getData =() =>{
    const { dispatch } = this.props;
    dispatch({
      type: 'monitor/fetch_current_mainten',
    });
  }

  // 任务详情
  handleTaskInfo = (id)=>{
    const { dispatch } = this.props;
    // const { formValues, currentPage} = this.state;
    router.push({ pathname:`/maintain/task/detail/info/${id}`});
  }

  render() {
    const { TableData, loading } = this.props;


    const columns = [{
      title: '名称',
      dataIndex: 'taskName',
      render: text=> <span>{text}</span>
    },{
      title: '编号',
      dataIndex: 'taskCode',
      render: text=> <span>{text}</span>
    },{
      title: '执行人',
      dataIndex: 'maintainManName',
      render: text=> <span>{text}</span>
    },{
      title: '状态',
      dataIndex: 'status',
      render: (text,row)=> <span>{row.signTaskDevCount}/{row.allTaskDevCount}</span>,
    }];



    return (
      <Card
        title={ <span><Badge status="processing" />当前养护</span>}
        bordered={false}
        bodyStyle={{padding:0}}
        hoverable={true}
        style={{marginTop:0}}
        className={styles.tablechart_card}
      >
        <Table className={styles.tablechartnormal}
               columns={columns}
               dataSource={TableData}
               pagination={false}
               size="small"
               rowKey={"taskId"}
               loading={loading}
               onRow={(record) => {
                 return {
                   onClick: () => {
                     // 点击行
                     this.handleTaskInfo(record.taskId)
                   },
                 };
               }}
        />
      </Card>
    );
  }
}
